package com.example.mykotlin

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.TextView

class MainActivity : AppCompatActivity() {
     lateinit var text : TextView ;

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        Thread(object : Runnable {
            override fun run() {
                TODO("Not yet implemented")
            }
        }).start()

        Thread{println()}
        .start()
         text = findViewById(R.id.text1);
        text.setText("dd");
        text.setOnClickListener {  };

        "obj".let { it -> //it就是obj
            //编写操作
        }
        TUtil.test2()
        HelloWorldKt.test();

        val list = listOf("apple, banana, orange")
        val result = with(StringBuilder()) {
            append("Start eating fruits.\n")
            for (fruit in list) {
                append(fruit).append("\n")
            }
            append("Ate all fruits")
            toString()
        }
        println(result)

        StringBuilder().let {
            it.append("Start eating fruits.\n")
        }
    }

    fun study(study: UserBean?) {
        study?.id = "4";
        //假设此时为空抛出异常，则和java一样
        study!!.doHomework()
        study!!.let {
            it.doHomework();
             it.id= "3";
        }

        with(study){
            doHomework();
        }
    }
    //全局变量
    var study: UserBean? = null
    fun study() {
        //报错
        if (study != null) {
            study?.doHomework()
        }


        val intent = Intent(this, MainActivity::class.java).apply {
            putExtra("param1", "data1");
            putExtra("param2", "data2");
        }
        startActivity(intent)

    }


}